import random
def guess_number_game():
    gold=5000
    playing=True
    while playing and gold >=500:
        target=random.randint(1,100)
        while True:
            guess=int(input("请输入猜测的数字（1-100）："))
            if guess>target:
                gold-=500
                print(f"大了！金币-500，剩余:{gold}")
            elif guess<target:
                gold-=500
                print(f"小了！金币-500,剩余:{gold}")
            else:
                gold+=3000
                print(f"\n恭喜猜中！幸运数字:{target}")
                print(f"获得奖励3000金币！当前金币:{gold}")
                break
            if gold <500:
                print(f"\n金币不足，无法继续游戏！")
                playing=False
                break
        if playing and gold>=500:
            while True:
                choice=input("\n是否继续下一轮?(y/n):").lower()
                if choice=="y":
                    print("-"*30+"\n")
                    break
                elif choice=="n":
                    playing=False
                    break
                else:
                    print("请输入y或n:")
    print("\n"+"="*30)
    print(f"游戏结束!最终金币:{gold}")
if __name__=="__main__":
    guess_number_game()
